import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sz/tools/tools.dart';

// 头部
class SzAppBar extends StatelessWidget implements PreferredSizeWidget {
  const SzAppBar({required this.title, this.onBack, super.key});

  final String title;
  final Function? onBack;

  @override
  Size get preferredSize => getSize();

  Size getSize() {
    return Size(rpx(750), rpx(100));
  }

  @override
  AppBar build(BuildContext context) {
    return AppBar(
      title: Text(
        title,
        style: const TextStyle(color: Colors.white),
      ),
      backgroundColor: SzColor.primary,
      centerTitle: true,
      leading: IconButton(
        onPressed: () {
          if (onBack != null) {
            onBack!();
          } else {
            Get.back();
          }
        },
        icon: Icon(
          Icons.chevron_left,
          color: Colors.white,
          size: setSp(60),
        ),
      ),
    );
  }
}
